var app = getApp();
Page({
  data: {
    
  },
  onLoad: function (options) {
    //获取手机高度
    this.setData({
      navH: app.globalData.navHeight
    })
  },
  //页面加载
  onReady: function () {
    
  },
  onShow: function () {
    var that = this;
    that.setData({
      token: wx.getStorageSync("token")
    });
    //热搜
    wx.request({
      url: app.globalData.url + "getHotSearchList",
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      data: {
      },
      method: "POST",
      success: function (res) {
        var data = res.data;
        if (data.result === 1) {
          that.setData({
            hotSearch: data.data,
          })
        }
      }
    });
    //历史搜索
    wx.request({
      url: app.globalData.url + "getSearchHisList",
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      data: {
        userId:wx.getStorageSync("userId")
      },
      method: "POST",
      success: function (res) {
        var data = res.data;
        if (data.result === 1) {
          that.setData({
            searchHis: data.data,
          })
        }
      }
    }); 
  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {
  },
  navBack: function () {
    wx.navigateBack({

    })
  },
  find: function (e) {
    var that = this;
    wx.navigateTo({
      url: '/pages/productListNew/productListNew?text=' + e.detail.value,
    })
  }, 
  find2: function (e) {
    var that = this;
    wx.navigateTo({
      url: '/pages/productListNew/productListNew?text=' + e.currentTarget.dataset.information,
    })
  }, 
  deleteSearchHis:function(){
    var that = this;
    //删除历史搜索
    wx.request({
      url: app.globalData.url + "userDeleteSearchHis",
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      data: {
        userId: wx.getStorageSync("userId")
      },
      method: "POST",
      success: function (res) {
        var data = res.data;
        if (data.result === 1) {
          //历史搜索
          wx.request({
            url: app.globalData.url + "getSearchHisList",
            header: {
              "content-type": "application/x-www-form-urlencoded"
            },
            data: {
              userId: wx.getStorageSync("userId")
            },
            method: "POST",
            success: function (res) {
              var data = res.data;
              if (data.result === 1) {
                that.setData({
                  searchHis: data.data,
                })
              }
            }
          }); 
        }
      }
    });
  },
});